const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    target: cc.Node = null;

    isLook: boolean;

    onLoad() {
        this.isLook = true
    }

    start() {
        if (this.target == null) {
            cc.log('target==null');
            this.enabled = false;
        }
    }

    update(dt: number) {
        if (!this.isLook) {
            return;
        }
        let sub = this.target.position.subtract(this.node.position);
        let radin = Math.atan2(sub.y, sub.x);
        let angle = radin / Math.PI * 180;
        this.node.angle = angle;
    }
}